<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>公告管理 - 社区健康系统</title>
  <link href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.2/css/all.min.css" rel="stylesheet">
  <link rel="stylesheet" href="/CommunityHealthSystem_war_exploded/static/css/style.css">
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f8f9fa;
      margin: 0;
      padding: 0;
    }

    header {
      background-color: #007bff;
      color: white;
      padding: 15px 20px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    }

    header h1 {
      margin: 0;
      font-size: 24px;
    }

    nav {
      display: flex;
      gap: 15px;
    }

    nav a {
      color: white;
      text-decoration: none;
      padding: 8px 12px;
      border-radius: 4px;
      transition: background-color 0.3s;
    }

    nav a:hover {
      background-color: rgba(255, 255, 255, 0.2);
    }

    .container {
      max-width: 1200px;
      margin: 20px auto;
      padding: 20px;
      background-color: white;
      border-radius: 8px;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    }

    .main-title {
      font-size: 2rem;
      font-weight: bold;
      color: #343a40;
      text-align: center;
      margin-bottom: 20px;
    }

    .message {
      padding: 10px;
      margin-bottom: 15px;
      border-radius: 4px;
      font-weight: bold;
    }

    .success {
      background-color: #d4edda;
      color: #155724;
      border: 1px solid #c3e6cb;
    }

    .error {
      background-color: #f8d7da;
      color: #721c24;
      border: 1px solid #f5c6cb;
    }

    .btn {
      padding: 8px 12px;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      text-decoration: none;
      display: inline-block;
      font-size: 14px;
      transition: background-color 0.3s;
    }

    .btn-primary {
      background-color: #007bff;
      color: white;
    }

    .btn-primary:hover {
      background-color: #0056b3;
    }

    .btn-danger {
      background-color: #dc3545;
      color: white;
    }

    .btn-danger:hover {
      background-color: #c82333;
    }

    .notice-table {
      width: 100%;
      border-collapse: collapse;
      margin-top: 20px;
    }

    .notice-table th,
    .notice-table td {
      padding: 10px;
      border: 1px solid #dee2e6;
      text-align: left;
    }

    .notice-table th {
      background-color: #f8f9fa;
      font-weight: bold;
    }

    .footer {
      text-align: center;
      padding: 20px;
      background-color: #f1f1f1;
      border-top: 1px solid #dee2e6;
      margin-top: 20px;
    }

    .notice-content {
      max-height: 100px;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .publish-time {
      font-size: 12px;
      color: #6c757d;
    }
  </style>
</head>

<body>
<header>
  <h1>社区健康系统</h1>
  <nav>
    <a href="index3.jsp">返回首页</a>
    <a href="ElderHealthOverview">查看老人状况</a>
    <a href="ElderOverview">老人管理</a>
  </nav>
</header>

<div class="container">
  <h2 class="main-title">公告管理</h2>

  <!-- 显示操作消息 -->
  <c:if test="${not empty message}">
    <div class="message success">${message}</div>
  </c:if>
  <c:if test="${not empty error}">
    <div class="message error">${error}</div>
  </c:if>

  <div class="text-right mb-3">
    <a href="publish_notice.jsp" class="btn btn-primary">
      <i class="fas fa-plus-circle mr-1"></i>发布新公告
    </a>
  </div>

  <table class="notice-table">
    <thead>
    <tr>
      <th>公告ID</th>
      <th>标题</th>
      <th>内容</th>
      <th>发布时间</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${notices}" var="notice">
      <tr>
        <td class="font-weight-bold">${notice.id}</td>
        <td class="font-weight-bold">${notice.title}</td>
        <td class="font-weight-bold notice-content">${notice.content}</td>
        <td class="font-weight-bold publish-time">${notice.publishTime}</td>
        <td>
          <form action="AdminDelete" method="post" onsubmit="return confirm('确定要删除这条公告吗？');">
            <input type="hidden" name="id" value="${notice.id}">
            <button type="submit" class="btn btn-danger">删除</button>
          </form>
        </td>
      </tr>
    </c:forEach>
    </tbody>
  </table>
</div>

<footer class="footer">
  <div>
    <span>&copy; 2023 社区健康系统. All rights reserved.</span>
  </div>
</footer>

</body>

</html>